<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-09-03 15:06
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetWxBarberStoreInfoDetailCriteria extends BaseCriterias
{

	private $params;
	public function __construct($storeId,$userId)
	{
		$this->params = [
			'store_id' => $storeId,
			'barber_id'  => $userId
		];
	}

	public function apply($model, RepositoryInterface $repository)
	{
		$storeId = $this->params['store_id'];
		$userId = $this->params['barber_id'];
		return $model->select(['id','username','mobile','nick','profile_video','portrait','profile_picture'])
			->with('picture:id,image','profileVideo:id,url,thumb','profilePicture:id,image')
			->with(['userStore'=>function($v)use($storeId,$userId){
				$v->where(['sid'=>$storeId,'uid'=>$userId,'rid'=>2])->with(['store'=>function($q)use($storeId){
					$q->select(['id','name','address','doorplate']);
				}]);
			}])
			->withCount(['order'=>function($v) use($storeId,$userId){
			$v->where(['store_id'=>$storeId,'barber_id'=>$userId,'status'=>2]);
		}])
			->withCount(['userLike'=>function($q)use($storeId,$userId){
				$q->where(['store_id'=>$storeId,'user_id'=>$userId]);
			}])
			->where('id','=',$userId);
	}
}